home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 45
/
Amiga Format CD45 (1999-09)(Future Publishing)(GB)(Track 1 of 2)[!][issue 1999-11].iso
/
-serious-
/
programming
/
basic
/
messages
/
prog_a.bb2
< prev
next >
Wrap
Text File
|
1999-08-09
|
3KB
|
84 lines
; RUN THIS FROM THE CLI ONCE COMPILED
; Run this program before the other one from the CLI, i.e.
; 1> run prog_a <RETURN>
; 1> run prog_b <RETURN>
; You will need blitzlibs:amigalibs.res resident
; **********************************************
; This program creates a public message port (so that other programs can
; talk to it, this is not required if the stuff that uses your message
; port is set up by yourself, i.e. commodities). It then waits for messages to
; arrive. Any messages that arrive get their number changed and returned.
; Once all messages are processed, the program ends.
; The message will come in this form
NEWTYPE.NrMessage
SystemMsg.Message
number.w
End NEWTYPE
; Declare a pointer to our message port
DEFTYPE.MsgPort *msgp
; Declare a pointer to the message
DEFTYPE.NrMessage *nrmsg
; Start of main program
; Try to create a message port: Name "NrPort", priority 0
*msgp = CreateMsgPort_
If *msgp = 0
NPrint "Could not create message port!"
End
End If
myportname$= "NrPort" ; NB: This string should not be changed, as the pointer
; in the message port structure will point to it!
*msgp\mp_Node\ln_Pri = 0
*msgp\mp_Node\ln_Name = &myportname$
AddPort_ *msgp ; Add message port to the list of public message ports
; Wait for a message to arrive
NPrint "A: Waiting for message to arrive..."
;WaitPort_ *msgp ; NB: You could alternatively do the following (allows you to
; wait for >1 message port). If using the following,
; you must compare returnMask to all the other masks you
; use, to check what has sent you the signal. I added
; checking for CTRL-C to show what to do!
msgpMask.l = 1 LSL *msgp\mp_SigBit
signalset.l = msgpMask | #SIGBREAKF_CTRL_C ; Add other signals to this using logical OR
returnMask.l = Wait_(signalset)
If returnMask = msgpMask
; Now one or more messages has arrived, try to collect as many
; messages as possible
*nrmsg = GetMsg_(*msgp)
While (*nrmsg)
; Read the message
NPrint "A: The value received was: ",*nrmsg\number
; Alter it
*nrmsg\number = Rnd(32000)
NPrint "A: Value changed to: ",*nrmsg\number
; Reply to message
ReplyMsg_ *nrmsg
; Now that we have replied, we cannot change or access the message any more!
*nrmsg = GetMsg_(*msgp)
Wend
End If
If returnMask = #SIGBREAKF_CTRL_C Then NPrint "You pressed CTRL-C!"
; Start clean up, use this next loop to clear port of all messages before
; removing it from public list, then deleting
*nrmsg = GetMsg_(*msgp)
While (*nrmsg)
ReplyMsg_ *nrmsg
*nrmsg = GetMsg_(*msgp)
Wend
RemPort_ *msgp ; remove port from list of public ports
DeleteMsgPort_ *msgp ; delete message port
NPrint "The end!"
End